﻿#include "net_state.h"
#include <stdio.h>
#include "../db_h/DBDEFINE.h"

net_state::net_state()
{

}

XINT net_state::get_net_state(XCHAR* input_ip)
{
    QNetworkInterface *qt_net_interface;
    qt_net_interface = new QNetworkInterface();
    int state1,state2,interface_flag;
    int flag=0;
    XString str;
    int net_flag;
    for(int i=0;i<qt_net_interface->allInterfaces().count();i++)
    {
        interface_flag=qt_net_interface->allInterfaces().at(i).flags();
        QList<QNetworkAddressEntry> list=qt_net_interface->allInterfaces().at(i).addressEntries();
        for(int j=0;j<list.count();j++)
        {
            QHostAddress ip=list.at(j).ip();
            if(ip.toString()==QStringEx::fromLocal8Bit(input_ip))
            {
                flag=1;
                break;
            }
        }
    }
    if(flag==0)
        net_flag=SYS_STATE_INVALID;
    else if(flag==1)
    {
        str=QString::number(interface_flag,16);
        state1=0x1&interface_flag;
        state2=0x2&interface_flag;
        if((state1|state2)==3)
        {
            net_flag=SYS_STATE_VALID;
        }else
            net_flag=SYS_STATE_INVALID;
    }
    return net_flag;
}
